package com.spundhan.xtrac.adapters;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.spundhan.xtrac.R;

public class MenuListAdapter extends ArrayAdapter<String> {

	Context thisContext;

	int inflatableRes = 0;

	int textViewRes = 0;

	LayoutInflater inflater = null;

	String options[] = { "Trips", "Expenses", "Reports", "Settings" };

	int icons[] = { R.drawable.trip, R.drawable.expense,
			R.drawable.report, R.drawable.settings };

	public MenuListAdapter(Context context, int resource,int textViewResId) {
		super(context, resource,textViewResId);
		thisContext = context;
		inflatableRes = resource;
		inflater = (LayoutInflater) thisContext
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}

	@Override
	public int getCount() {
		return options.length;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {

		ViewHolder holder = null;

		try {
			if (convertView == null) {

				holder = new ViewHolder();
				convertView = inflater.inflate(inflatableRes, null);
				convertView.setTag(holder);

				holder.optionImage = (ImageView) convertView
						.findViewById(R.id.image_option);
				holder.optionText = (TextView) convertView
						.findViewById(R.id.text_option);

			} else {

				holder = (ViewHolder) convertView.getTag();
			}

			holder.optionImage.setImageResource(icons[position]);
			holder.optionText.setText(options[position]);

		} catch (Exception e) {

			e.printStackTrace();
		}

		return convertView;
	}

	public class ViewHolder {

		ImageView optionImage;
		TextView optionText;

	}
}
